﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using devtm.Collections;
using System.IO;

namespace devtm.Types.LazyLoading
{

    
    public class stLDirectories : TableCollection<Directory, string>
    {


        private ClsGetTypes root;

        public stLDirectories(ClsGetTypes root) : base(c => c.DirectoryItem.FullName) 
        {
            this.root = root;
            GlobalAssemblyCash gac = new GlobalAssemblyCash();

            foreach (AssemblyDescription item in gac.Assemblies())
            {
                if (item.processorArchitecture != "x86")
                    continue;
                var v = new AssemblyGacNamespace(item);

                if (!v.IsInError && !stLDirectories.Assemblies.ContainsKey(v.Filename))
                    try
                    {
                        stLDirectories.Assemblies.Add(v);
                    }
                    catch (Exception ex)
                    {
                        
                        throw;
                    }
                   
            }
            
        }


        internal Directory Add(DirectoryInfo directory)
        {

            if (this.ContainsKey(directory.FullName))
                return this[directory.FullName];

            Directory d = new Directory(directory, root);

            this.Add(d);

            return d;

        }


        //public IEnumerable<FileItem> GetFiles()
        //{

        //    foreach (Directory dir in this)
        //        foreach (FileItem file in dir.GetFiles())
        //            yield return file;
            
        //}

        public static AssembliesNames Assemblies = new AssembliesNames();


        public void Create(DirectoryInfo item)
        {
            this.Add(new devtm.Types.LazyLoading.Directory(item, root));
        }
    }
}
